//
//  RootViewController.m
//  HTML
//
//  Created by 黄军 on 17/4/7.
//  Copyright © 2017年 $. All rights reserved.
//

#import "RootViewController.h"
@interface RootViewController ()<UIWebViewDelegate>

@property(nonatomic,strong)UIWebView *webView;

@end

@implementation RootViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    [self createWebView];
}

-(void)createWebView{
    self.webView  = [[UIWebView alloc]init];
    self.webView.delegate = self;
    self.webView.frame =CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.x+20, self.view.bounds.size.width, self.view.bounds.size.height-69);
    
    NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"HTML/index" ofType:@"html" inDirectory:nil]];
    
//    NSURL *url = [NSURL URLWithString:@"http://www.zo26.cn"];
    
    
    NSURLRequest * request = [NSURLRequest requestWithURL:url];
    
    [self.webView loadRequest:request];
    
    [self.view addSubview:self.webView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    NSLog(@"%@",request.URL);
    
    return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
    NSLog(@"开始请求");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    NSLog(@"请求完成");
//    NSString *swizzleCloseWindowJS =
//    @"var script = document.createElement('script');"
//    "script.type = 'text/javascript';"
//    "script.text = \"window.close = function windowOnClose() { "
//    "javascript:window.location='hackCloseWindowFrame://'"
//    "}\";"
//    "document.getElementsByTagName('head')[0].appendChild(script);";
//    [webView stringByEvaluatingJavaScriptFromString:swizzleCloseWindowJS];
//    
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    NSLog(@"请求失败：%@",error.userInfo);
}

//-(NSURL *)loadString:(NSString *)URL{
//    if ([URL hasPrefix:@"http://"]||[URL hasPrefix:@"https://"]) {
//        return [NSURL URLWithString:URL];
//    }else{
//        return  [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"HTML/index" ofType:@"html" inDirectory:nil]];
//    }
//}


@end
